package com.lzx.dormsys.controller;

import java.util.List;

import com.lzx.dormsys.bean.SysDeptBean;
import com.lzx.dormsys.core.AjaxResult;
import com.lzx.dormsys.core.controller.BaseController;
import com.lzx.dormsys.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lzx.dormsys.service.ISysDeptBeanService;

/**
 * 部门Controller
 *
 * @author ruoyi
 * @date 2021-09-09
 */
@RestController
@RequestMapping("/system/dept")
public class SysDeptBeanController extends BaseController
{
    @Autowired
    private ISysDeptBeanService sysDeptBeanService;

    /**
     * 查询部门列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysDeptBean sysDeptBean)
    {
        startPage();
        List<SysDeptBean> list = sysDeptBeanService.selectSysDeptBeanList(sysDeptBean);
        return getDataTable(list);
    }

    /**
     * 获取部门详细信息
     */
    @GetMapping(value = "/{deptId}")
    public AjaxResult getInfo(@PathVariable("deptId") Long deptId)
    {
        return AjaxResult.success(sysDeptBeanService.selectSysDeptBeanById(deptId));
    }

    /**
     * 新增部门
     */
    @PostMapping
    public AjaxResult add(@RequestBody SysDeptBean sysDeptBean)
    {
        return toAjax(sysDeptBeanService.insertSysDeptBean(sysDeptBean));
    }

    /**
     * 修改部门
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SysDeptBean sysDeptBean)
    {
        return toAjax(sysDeptBeanService.updateSysDeptBean(sysDeptBean));
    }

    /**
     * 删除部门
     */
	@DeleteMapping("/{deptIds}")
    public AjaxResult remove(@PathVariable Long[] deptIds)
    {
        return toAjax(sysDeptBeanService.deleteSysDeptBeanByIds(deptIds));
    }

    @GetMapping("/treeselect")
    public AjaxResult treeselect(SysDeptBean dept)
    {
        List<SysDeptBean> sysDeptBeans = sysDeptBeanService.selectSysDeptBeanList(dept);
        return AjaxResult.success(sysDeptBeanService.buildDeptTreeSelect(sysDeptBeans));
    }
}
